Public Class RubroEvaluacion
    Inherits ComponenteEvaluacion

    Private midRubro As Integer
    Private mnombre As String
    Private mporcentaje As Integer
    Private midPlan As Integer
    Private mlistaRubros As List(Of ComponenteEvaluacion)

    Public Sub New()
        mlistaRubros = New List(Of ComponenteEvaluacion)
    End Sub

    Public Sub New(ByVal pidRubro As Integer, ByVal pporcentaje As Double, ByVal pidPlan As Integer, ByVal pnombre As String)
        Me.midRubro = pidRubro
        Me.Nombre = pnombre
        Me.Porcentaje = pporcentaje
        Me.IdPlan = pidPlan
        mlistaRubros = New List(Of ComponenteEvaluacion)
    End Sub
    Public Sub New(ByVal pporcentaje As Double, ByVal pidRubro As Integer, ByVal pnombre As String)
        Me.Nombre = pnombre
        Me.Porcentaje = pporcentaje
        Me.midRubro = pidRubro
        Me.IdPlan = pidRubro
        mlistaRubros = New List(Of ComponenteEvaluacion)
    End Sub

    Public Overrides Sub Add(ByVal pcomponenteEvaluacion As ComponenteEvaluacion)
        mlistaRubros.Add(pcomponenteEvaluacion)
    End Sub

    Public Overrides Sub Remove(ByVal pcomponenteEvaluacion As ComponenteEvaluacion)
        mlistaRubros.Remove(pcomponenteEvaluacion)
    End Sub

    Public Overrides Function GetChild(ByVal index As String) As ComponenteEvaluacion
        Dim i As Integer = 0
        Dim hijo As New ComponenteEvaluacion

        For Each comp As ComponenteEvaluacion In mlistaRubros
            If comp.Nombre.Equals(index) Then
                hijo = mlistaRubros.Item(i)
            End If
            i = i + 1
        Next comp
        Return hijo
    End Function

    Public Overrides Function CalcularNota() As Double
        Dim suma As Double
        suma = 0
        For Each comp As ComponenteEvaluacion In mlistaRubros
            suma += comp.Porcentaje
        Next
        suma = suma * Me.Porcentaje
        suma = suma / mlistaRubros.Count
        suma = suma / 100
        Return suma
    End Function

    Public Overrides Property IdPlan() As Integer
        Get
            Return midPlan
        End Get
        Set(ByVal value As Integer)
            Me.midPlan = value
        End Set
    End Property

    Public Overrides Property Nombre() As String
        Get
            Return mnombre
        End Get
        Set(ByVal value As String)
            Me.mnombre = value
        End Set
    End Property

    Public Overrides Property ListaRubros() As List(Of ComponenteEvaluacion)
        Get
            'If (mlistaRubros Is Nothing) Then
            If (mlistaRubros.Count = 0) Then
                MultiPlan.LevantarEvaluacionesXRubro(Me.midRubro)
            End If
            Return mlistaRubros
        End Get
        Set(ByVal value As List(Of ComponenteEvaluacion))
            Me.mlistaRubros = value
        End Set
    End Property

    Public Overrides Property Porcentaje() As Double
        Get
            Return mporcentaje
        End Get
        Set(ByVal value As Double)
            Me.mporcentaje = value
        End Set
    End Property



End Class
